{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 1 1 1 1 1\n"
     ]
    }
   ],
   "source": [
    "s = 2\n",
    "a = [s] + [1]*5\n",
    "print(*a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1] + [2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "celoss = torch.nn.CrossEntropyLoss()\n",
    "pred = torch.tensor([[0.1, 0.3, 0.6], [0.1, 0.8, 0.1], [0.1, 0.2, 0.7]])\n",
    "labels = torch.tensor([0, 1, 2])\n",
    "loss = celoss(pred, labels)\n",
    "loss.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[tensor([1.]), tensor([2.])]\n",
      "tensor([1., 2.])\n"
     ]
    }
   ],
   "source": [
    "a = torch.Tensor([1])\n",
    "b = torch.Tensor([2])\n",
    "c = []\n",
    "c.append(a)\n",
    "c.append(b)\n",
    "print(c)\n",
    "d = torch.cat(c, dim=0)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0.7000, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.7000, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.7000, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.7000, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.7000, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.7000, 0.0333, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.7000, 0.0333, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.7000, 0.0333,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.7000,\n",
      "         0.0333],\n",
      "        [0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333, 0.0333,\n",
      "         0.7000]], grad_fn=<CopySlices>)\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "import torch.nn.functional as F\n",
    "\n",
    "noise_adaption = torch.nn.Parameter(torch.zeros(10, 9))\n",
    "teacher_acc = torch.Tensor([0.7])\n",
    "noise_adaption_softmax = F.softmax(noise_adaption, dim=1) * (1-teacher_acc)\n",
    "\n",
    "noise_adaption_layer = torch.zeros(10, 10)\n",
    "\n",
    "for i in range(10):\n",
    "    #第一行\n",
    "    if i == 0:\n",
    "        noise_adaption_layer[i] = torch.cat([teacher_acc, noise_adaption_softmax[i][i:]])\n",
    "    if i == 9:\n",
    "        noise_adaption_layer[i] = torch.cat([noise_adaption_softmax[i][:i], teacher_acc])\n",
    "    else:\n",
    "        noise_adaption_layer[i] = torch.cat([noise_adaption_softmax[i][:i], teacher_acc, noise_adaption_softmax[i][i:]])\n",
    "\n",
    "print(noise_adaption_layer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torchvision.datasets import CIFAR10, CIFAR100, ImageFolder\n",
    "import torchvision.transforms as transforms\n",
    "transform_train = transforms.Compose([\n",
    "\t\t\t\ttransforms.RandomCrop(32, padding=4),\n",
    "\t\t\t\ttransforms.RandomHorizontalFlip(),\n",
    "\t\t\t\ttransforms.ToTensor(),\n",
    "\t\t\t\ttransforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),\n",
    "\t\t\t\t])\n",
    "\n",
    "dataset_train = CIFAR10('/home/ubuntu/datasets', transform=transform_train, download=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 0.1346,  0.9274,  0.4694,  0.6224],\n",
      "         [ 0.9558,  0.0269, -1.3040, -1.3778],\n",
      "         [-0.5126, -0.4741,  0.3212,  0.6842]],\n",
      "\n",
      "        [[ 1.2724, -0.3609,  0.2959,  1.5027],\n",
      "         [ 0.0995,  1.5858, -0.6697,  0.2166],\n",
      "         [-0.5268, -0.7467,  2.0048, -1.9143]]])\n",
      "tensor([[[ 0.9274,  0.4694,  0.6224],\n",
      "         [ 0.0269, -1.3040, -1.3778],\n",
      "         [-0.4741,  0.3212,  0.6842]],\n",
      "\n",
      "        [[-0.3609,  0.2959,  1.5027],\n",
      "         [ 1.5858, -0.6697,  0.2166],\n",
      "         [-0.7467,  2.0048, -1.9143]]])\n",
      "tensor([[[ 0.1346,  0.9274,  0.4694],\n",
      "         [ 0.9558,  0.0269, -1.3040],\n",
      "         [-0.5126, -0.4741,  0.3212]],\n",
      "\n",
      "        [[ 1.2724, -0.3609,  0.2959],\n",
      "         [ 0.0995,  1.5858, -0.6697],\n",
      "         [-0.5268, -0.7467,  2.0048]]])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "a = torch.randn((2, 3, 4))\n",
    "print(a)\n",
    "print(a[:,:,1:])\n",
    "print(a[:,:,:-1])"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "b616bc69f5e56e869b6afa9b75bee44fb0b9cfffce48900ded2d9beddfe2e77a"
  },
  "kernelspec": {
   "display_name": "Python 3.6.13 64-bit ('torch-1.7': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
